package com.ltmall.api.interceptor;

import com.ltmall.api.manager.AccountManager;
import com.ltmall.api.manager.SubUnderwritingManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

/**
 * 经销商拦截器 - 负责处理经销商带来的链接并建立关系
 *
 * @author x1ny
 */
public class UnderwriterInterceptor extends HandlerInterceptorAdapter {

    private AccountManager accountManager;
    private SubUnderwritingManager subUnderwritingManager;
    private Logger logger = LogManager.getLogger(UnderwriterInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        logger.debug("请求：" + request.getRequestURI());
        Enumeration parameterNames = request.getParameterNames();
        String str = "线程： " + String.valueOf(Thread.currentThread().getId()) + " ";
        while (parameterNames.hasMoreElements()) {
            String parameterName = (String) parameterNames.nextElement();
            String parameterValue = request.getParameter(parameterName);
            str += parameterName + ": " + parameterValue + ";";
        }
        logger.debug(str);
        System.out.println(str);
        return true;

    }

    public AccountManager getAccountManager() {
        return accountManager;
    }

    public void setAccountManager(AccountManager accountManager) {
        this.accountManager = accountManager;
    }

    public SubUnderwritingManager getSubUnderwritingManager() {
        return subUnderwritingManager;
    }

    public void setSubUnderwritingManager(SubUnderwritingManager subUnderwritingManager) {
        this.subUnderwritingManager = subUnderwritingManager;
    }
}
